package com.ydm.fire_fighting_web.modules.index.service.impl;

import com.ydm.fire_fighting_web.entity.index.Equipments;
import com.ydm.fire_fighting_web.entity.index.EventInformation;
import com.ydm.fire_fighting_web.entity.index.FireFightingEquipment;
import com.ydm.fire_fighting_web.modules.index.mapper.IndexMapper;
import com.ydm.fire_fighting_web.modules.index.service.IndexService;
import com.ydm.fire_fighting_web.util.TimeUil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional(rollbackFor = RuntimeException.class)
public class IndexServiceImpl implements IndexService {
    @Autowired
    private IndexMapper indexMapper;

    public Equipments findAllEquipment() {
        Equipments equipments = new Equipments();
        Integer number0 = indexMapper.findStatus(0);
        Integer number1 = indexMapper.findStatus(1);
        Integer number2 = indexMapper.findStatus(2);
        Integer number3 = indexMapper.findStatus(3);
        equipments.setNumber0(number0);
        equipments.setNumber1(number1);
        equipments.setNumber2(number2);
        equipments.setNumber3(number3);
        equipments.setEquipmentSum(number0+number1+number2+number3);
        return equipments;
    }

    public List<FireFightingEquipment> findTOPTenEquipment(String lastTime) {
        String format = TimeUil.ComputationTime(lastTime);
        List<FireFightingEquipment> equipmentList = indexMapper.findTOPTenEquipment(format);
        return equipmentList;
    }

    public List<EventInformation> findTenEventInformation(String lastTime) {
        String format = TimeUil.ComputationTime(lastTime);
        List<EventInformation> eventInformations = indexMapper.findTenEventInformation(format);
        return eventInformations;
    }

    public List<FireFightingEquipment> findAllBadEquipment() {
        List<FireFightingEquipment> equipmentList =  indexMapper.findAllBadEquipment();
        return equipmentList;
    }
}
